package com.wbdgj.ui.home;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Button;

import com.google.gson.internal.LinkedTreeMap;
import com.igexin.sdk.PushManager;
import com.wbdgj.R;
import com.wbdgj.adapter.NoticeAdapter;
import com.wbdgj.base.BaseActivity;
import com.wbdgj.base.BaseApplication;
import com.wbdgj.http.HttpAdapter;
import com.wbdgj.http.OnNoResponseListener;
import com.wbdgj.http.OnResponseListener;
import com.wbdgj.model.ResultObjectModel;
import com.wbdgj.ui.login.LoginActivity;
import com.wbdgj.utils.SpKeyUtils;
import com.wbdgj.utils.ToastUtils;
import com.wbdgj.utils.refresh.PullListView;
import com.wbdgj.utils.refresh.PullToRefreshLayout;

import java.text.DecimalFormat;
import java.util.ArrayList;

import butterknife.BindView;
import retrofit2.Call;

public class NewsAllActivity extends BaseActivity {

    private Context context = this;

    @BindView(R.id.zhtzNum)
    Button zhtzNum;
    @BindView(R.id.hdNum)
    Button hdNum;
    @BindView(R.id.xxtzNum)
    Button xxtzNum;
    private DecimalFormat decimalFormat;
    @Override
    protected int getLayoutResId() {
        return R.layout.ui_notice_all;
    }

    @Override
    protected void initView() {
        decimalFormat = new DecimalFormat("###################.###########");
        findViewById(R.id.zhtzLay).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                launch(NewsActivity.class);
            }
        });
        findViewById(R.id.xxtzLay).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                launch(NewsXtxxActivity.class);
            }
        });
        findViewById(R.id.hdxxLay).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                ToastUtils.toastShort("暂无活动消息通知");
                launch(NewsCampaignActivity.class);
            }
        });
        appmbmsgcnt();
        appmbmsgcnt1();
        appsysmsg();
    }

//    private void appmbmsgcnt() {
//        Call<ResultObjectModel> call01 = HttpAdapter.getSerives().appmbmsgcnt(BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.TOKEN));
//        call01.enqueue(new OnNoResponseListener<ResultObjectModel>(context) {
//            @Override
//            protected void onSuccess(ResultObjectModel userModelBaseResultModel) {
//                if(userModelBaseResultModel.getResultCode().equals("0000")){
//                    DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
//                    LinkedTreeMap linkedTreeMap = (LinkedTreeMap) userModelBaseResultModel.getData();
//                    zhtzNum.setText(decimalFormat.format(linkedTreeMap.get("CNT")));
//                }else if (userModelBaseResultModel.getResultCode().equals("1111")){
//                    ToastUtils.toastShort("账号没有登录或在其它地方登录");
//                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.TOKEN, "");
//                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.IS_AUTO_LOGIN, "2");
//                    PushManager.getInstance().unBindAlias(context, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.LOGIN_PHONE), false, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CID));
//                    Intent intent = new Intent(context, LoginActivity.class);
//                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
//                    startActivity(intent);
//                }
//            }
//        });
//    }

    private void appsysmsg() {
        Call<ResultObjectModel> call = HttpAdapter.getSerives().appsysmsg("10", "1");
        call.enqueue(new OnResponseListener<ResultObjectModel>(context) {
            @Override
            protected void onSuccess(ResultObjectModel userModelBaseResultModel) {
                if(userModelBaseResultModel.getResultCode().equals("0000")){
                    LinkedTreeMap linkedTreeMap = (LinkedTreeMap) userModelBaseResultModel.getData();
                    LinkedTreeMap pageLinkedTreeMap = (com.google.gson.internal.LinkedTreeMap) linkedTreeMap.get("page");
                    xxtzNum.setText(decimalFormat.format(pageLinkedTreeMap.get("totalCount")));
                }else if (userModelBaseResultModel.getResultCode().equals("1111")){
                    ToastUtils.toastShort("账号没有登录或在其它地方登录");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.TOKEN, "");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.IS_AUTO_LOGIN, "2");
                    PushManager.getInstance().unBindAlias(context, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.LOGIN_PHONE), false, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CID));
                    Intent intent = new Intent(context, LoginActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }else{
                    ToastUtils.toastShort(userModelBaseResultModel.getResultMsg());
                }
            }
        });
    }

    private void appmbmsgcnt() {
        Call<ResultObjectModel> call = HttpAdapter.getSerives().appmbmsglist("0", "10", "1",BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.TOKEN));
        call.enqueue(new OnResponseListener<ResultObjectModel>(context) {
            @Override
            protected void onSuccess(ResultObjectModel userModelBaseResultModel) {
                if(userModelBaseResultModel.getResultCode().equals("0000")){
                    LinkedTreeMap linkedTreeMap = (LinkedTreeMap) userModelBaseResultModel.getData();
                    LinkedTreeMap pageLinkedTreeMap = (com.google.gson.internal.LinkedTreeMap) linkedTreeMap.get("page");
                    zhtzNum.setText(decimalFormat.format(pageLinkedTreeMap.get("totalCount")));
                }else if (userModelBaseResultModel.getResultCode().equals("1111")){
                    ToastUtils.toastShort("账号没有登录或在其它地方登录");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.TOKEN, "");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.IS_AUTO_LOGIN, "2");
                    PushManager.getInstance().unBindAlias(context, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.LOGIN_PHONE), false, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CID));
                    Intent intent = new Intent(context, LoginActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }else{
                    ToastUtils.toastShort(userModelBaseResultModel.getResultMsg());
                }
            }
        });
    }

    private void appmbmsgcnt1() {
        Call<ResultObjectModel> call = HttpAdapter.getSerives().appmbmsglist("1", "10", "1",BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.TOKEN));
        call.enqueue(new OnResponseListener<ResultObjectModel>(context) {
            @Override
            protected void onSuccess(ResultObjectModel userModelBaseResultModel) {
                if(userModelBaseResultModel.getResultCode().equals("0000")){
                    LinkedTreeMap linkedTreeMap = (LinkedTreeMap) userModelBaseResultModel.getData();
                    LinkedTreeMap pageLinkedTreeMap = (com.google.gson.internal.LinkedTreeMap) linkedTreeMap.get("page");
                    hdNum.setText(decimalFormat.format(pageLinkedTreeMap.get("totalCount")));
                }else if (userModelBaseResultModel.getResultCode().equals("1111")){
                    ToastUtils.toastShort("账号没有登录或在其它地方登录");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.TOKEN, "");
                    BaseApplication.getInstance().getSpUtil().putString(SpKeyUtils.IS_AUTO_LOGIN, "2");
                    PushManager.getInstance().unBindAlias(context, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.LOGIN_PHONE), false, BaseApplication.getInstance().getSpUtil().getString(SpKeyUtils.CID));
                    Intent intent = new Intent(context, LoginActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }else{
                    ToastUtils.toastShort(userModelBaseResultModel.getResultMsg());
                }
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
    }
}
